home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_mysql.idb / usr / freeware / include / mysql / raid.h.z / raid.h
C/C++ Source or Header  |  2002-10-07  |  6KB  |  162 lines

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2.  
  3.    This library is free software; you can redistribute it and/or
  4.    modify it under the terms of the GNU Library General Public
  5.    License as published by the Free Software Foundation; either
  6.    version 2 of the License, or (at your option) any later version.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public
  14.    License along with this library; if not, write to the Free
  15.    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  16.    MA 02111-1307, USA */
  17.  
  18. /* Parser needs these defines  always, even if USE_RAID is not defined */
  19. #define RAID_TYPE_0 1       /* Striping */
  20. #define RAID_TYPE_x 2       /* Some new modes */
  21. #define RAID_TYPE_y 3
  22.  
  23. #define RAID_DEFAULT_CHUNKS 4
  24. #define RAID_DEFAULT_CHUNKSIZE 256*1024 /* 256kB */
  25.  
  26. extern const char *raid_type_string[];
  27.  
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. const char *my_raid_type(int raid_type);
  32. #ifdef __cplusplus
  33. }
  34. #endif
  35.  
  36. #if defined(USE_RAID) && !defined(DONT_USE_RAID)
  37.  
  38. #ifdef __GNUC__
  39. #pragma interface            /* gcc class implementation */
  40. #endif
  41. #include "my_dir.h"
  42.  
  43. /* Trap all occurences of my_...() in source and use our wrapper around this function */
  44.  
  45. #ifdef MAP_TO_USE_RAID
  46. #define my_read(A,B,C,D)     my_raid_read(A,B,C,D)
  47. #define my_write(A,B,C,D)    my_raid_write(A,B,C,D)
  48. #define my_pwrite(A,B,C,D,E) my_raid_pwrite(A,B,C,D,E)
  49. #define my_pread(A,B,C,D,E)  my_raid_pread(A,B,C,D,E)
  50. #define my_chsize(A,B,C)     my_raid_chsize(A,B,C)
  51. #define my_close(A,B)        my_raid_close(A,B)
  52. #define my_tell(A,B)         my_raid_tell(A,B)
  53. #define my_seek(A,B,C,D)     my_raid_seek(A,B,C,D)
  54. #define my_lock(A,B,C,D,E)     my_raid_lock(A,B,C,D,E)
  55. #define my_fstat(A,B,C)     my_raid_fstat(A,B,C)
  56. #endif /* MAP_TO_USE_RAID */
  57.  
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61.  
  62.   void init_raid(void);
  63.   void end_raid(void);
  64.  
  65.   bool is_raid(File fd);
  66.   File my_raid_create(const char *FileName, int CreateFlags, int access_flags,
  67.               uint raid_type, uint raid_chunks, ulong raid_chunksize,
  68.               myf MyFlags);
  69.   File my_raid_open(const char *FileName, int Flags,
  70.             uint raid_type, uint raid_chunks, ulong raid_chunksize,
  71.             myf MyFlags);
  72.   int my_raid_rename(const char *from, const char *to, uint raid_chunks,
  73.              myf MyFlags);
  74.   int my_raid_delete(const char *from, uint raid_chunks, myf MyFlags);
  75.   int my_raid_redel(const char *old_name, const char *new_name,
  76.             uint raid_chunks, myf MyFlags);
  77.  
  78.   my_off_t my_raid_seek(File fd, my_off_t pos, int whence, myf MyFlags);
  79.   my_off_t my_raid_tell(File fd, myf MyFlags);
  80.  
  81.   uint my_raid_write(File,const byte *Buffer, uint Count, myf MyFlags);
  82.   uint my_raid_read(File Filedes, byte *Buffer, uint Count, myf MyFlags);
  83.  
  84.   uint my_raid_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
  85.              myf MyFlags);
  86.   uint my_raid_pwrite(int Filedes, const byte *Buffer, uint Count,
  87.               my_off_t offset, myf MyFlags);
  88.  
  89.   int my_raid_lock(File,int locktype, my_off_t start, my_off_t length,
  90.            myf MyFlags);
  91.   int my_raid_chsize(File fd, my_off_t newlength, myf MyFlags);
  92.   int my_raid_close(File, myf MyFlags);
  93.   int my_raid_fstat(int Filedes, struct stat *buf,  myf MyFlags);
  94.  
  95. #ifdef __cplusplus
  96. }
  97.  
  98. class RaidName {
  99.   public:
  100.     RaidName(const char *FileName);
  101.     ~RaidName();
  102.     bool IsRaid();
  103.     int Rename(const char * from, const char * to, myf MyFlags);
  104.   private:
  105.     uint _raid_type;       /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */
  106.     uint _raid_chunks;     /* 1..n */
  107.     ulong _raid_chunksize; /* 1..n in bytes */
  108. };
  109.  
  110. class RaidFd {
  111.   public:
  112.     RaidFd(uint raid_type, uint raid_chunks , ulong raid_chunksize);
  113.     ~RaidFd();
  114.     File Create(const char *FileName, int CreateFlags, int access_flags,
  115.         myf MyFlags);
  116.     File Open(const char *FileName, int Flags, myf MyFlags);
  117.     my_off_t Seek(my_off_t pos,int whence,myf MyFlags);
  118.     my_off_t Tell(myf MyFlags);
  119.     int Write(const byte *Buffer, uint Count, myf MyFlags);
  120.     int Read(const byte *Buffer, uint Count, myf MyFlags);
  121.     int Lock(int locktype, my_off_t start, my_off_t length, myf MyFlags);
  122.     int Chsize(File fd, my_off_t newlength, myf MyFlags);
  123.     int Fstat(int fd, MY_STAT *stat_area, myf MyFlags );
  124.     int Close(myf MyFlags);
  125.     static bool IsRaid(File fd);
  126.     static DYNAMIC_ARRAY _raid_map;        /* Map of RaidFD* */
  127.   private:
  128.  
  129.     uint _raid_type;       /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */
  130.     uint _raid_chunks;     /* 1..n */
  131.     ulong _raid_chunksize; /* 1..n in bytes */
  132.  
  133.     ulong _total_block;    /* We are operating with block no x (can be 0..many). */
  134.     uint _this_block;      /* can be 0.._raid_chunks */
  135.     uint _remaining_bytes; /* Maximum bytes that can be written in this block */
  136.  
  137.     my_off_t _position;
  138.     my_off_t _size;        /* Cached file size for faster seek(SEEK_END) */
  139.     File _fd;
  140.     File *_fd_vector;        /* Array of File */
  141.     off_t *_seek_vector;    /* Array of cached seek positions */
  142.  
  143.     inline void Calculate()
  144.     {
  145.       DBUG_ENTER("RaidFd::_Calculate");
  146.       DBUG_PRINT("info",("_position: %lu _raid_chunksize: %d, _size: %lu",
  147.              (ulong) _position, _raid_chunksize, (ulong) _size));
  148.  
  149.       _total_block = (ulong) (_position / _raid_chunksize);
  150.       _this_block = _total_block % _raid_chunks;    /* can be 0.._raid_chunks */
  151.       _remaining_bytes = (uint) (_raid_chunksize -
  152.                  (_position - _total_block * _raid_chunksize));
  153.       DBUG_PRINT("info",
  154.          ("_total_block: %d  this_block: %d  _remaining_bytes:%d",
  155.           _total_block, _this_block, _remaining_bytes));
  156.       DBUG_VOID_RETURN;
  157.     }
  158. };
  159.  
  160. #endif /* __cplusplus */
  161. #endif /* USE_RAID */
  162.